package cn.com.ctcloud.saas.filter;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class AccessFilter extends ZuulFilter {

	private static Logger log = LoggerFactory.getLogger(AccessFilter.class);

	@Override
	public String filterType() {
		return "pre";
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public boolean shouldFilter() {
		return false;
	}

	@Override
	public Object run() {
		final RequestContext ctx = RequestContext.getCurrentContext();
		final HttpServletRequest request = ctx.getRequest();

		AccessFilter.log
				.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));

		final Object accessToken = request.getParameter("accessToken");
		AccessFilter.log.info(accessToken.toString());
		//        if(accessToken == null) {
		//            log.warn("access token is empty");
		//            ctx.setSendZuulResponse(false);
		//            ctx.setResponseStatusCode(401);
		//            return null;
		//        }
		AccessFilter.log.info("access token ok");
		return null;
	}

}
